GBML manual / Arrays

array_min

Gives back the smallest number target has: array_min(scores) of 7, 3 and 9 is 3. Use it for the lowest cooldown or the shortest distance.

Syntax

array_min(target) -> element

Arguments

NameType
targetarray

Returns

element

Description

Gives back the smallest number in target, an array. array_min(scores) of 7, 3 and 9 is 3. Use it for the lowest cooldown or the shortest distance.

Example

var scores = array_create(3, 0);
scores[0] = 7;
scores[1] = 3;
scores[2] = 9;
var answer = array_min(scores);   // 3

The small print

Cost

One pass over the items.

On the GBA

One pass from the first item to the last, keeping the smallest seen so far - nothing is changed or copied. For a array of array_length(target) items it takes that many comparisons. Whole numbers and decimals only; text, yes-or-no values, structs and references are refused when the project is checked. An empty one gives back 0.

See also: array_sortarray_maxarray_sumlist_minarray_lengthArraysData containers